import React, { useEffect, useState } from 'react'
import {useLocation,useHistory} from 'react-router-dom'
import useStore from '../context/useStore'
import './my.scss'
const My:React.FC=()=>{
    let location=useLocation()
    let [obja,setObja]=useState(Object)
    let history=useHistory()
    let {mine}=useStore()
    useEffect(()=>{
        setObja(location.state)
    })
    console.log(obja)
    //点击事件
    function gologin(){
        history.push('/login')
    }
    //点击退出登录
    function del(){
        mine.delD().then(res=>{
            console.log(res)
            if(res.data.result==0){
                history.push('/mine')
            }
        })
    }
    //点击昵称
    function change(){
        history.push({
            pathname:'/change',
            state:{...obja}
        })
    }
    return  <div className='wrap'>
               <div className='header'>
                      <div onClick={()=>{history.goBack()}} className='push'>
                          {
                              '<'
                          }
                      </div>
                      <div className='text'>
                        我的资料
                      </div>
               </div>
               <div className='main'>
                   <div>
                       <div>头像</div>
                       <div><img src={obja&&obja.avatar} alt=""/></div>
                   </div>
                   <div onClick={change}>
                       <span>昵称</span>
                       <span>{obja&&obja.nickname}</span>
                   </div>
                   <div onClick={gologin}>
                       <span>手机号</span>
                       <span>{obja&&obja.mobile}</span>
                   </div>
                   <div>
                        <button className='btn' onClick={del}>退出登录</button>
                    </div>
               </div>
               
            </div>
   
}
export default My